package ThreadSafety;

public class SynchronizedLocker2 {
    public static int res = 0;
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Object locker1 = new Object();

        Thread t = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                synchronized (locker){
                    res++;
                }
            }
        });

        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                synchronized (locker1) {
                    res++;
                }
            }
        });

        t.start();
        t1.start();
        t.join();
        t1.join();
        System.out.println(res);
    }
}
